<!-- Copyright: 8210 studios 
By Emil and Marek-->
<?php
    require('connect_db.php');
?>

<!DOCTYPE html ->
<html>
    <head>
        <title>My Limit - Login</title>
        <link rel="stylesheet" type="text/css" href="css/index.css">
    </head>
    <body>

    <br/><br/><br/><br/>
        <!-- this is the wrapper for all the elements -->
    	<div id="main-frame">
            <div id="logo-text">
                <h1>MyLimit</h1>
            </div>
            
            <!-- the main part under the header -->

            <div id="right-frame">

            <form method="post" action="index.php" enctype="multipart/form-data">
                <input type="text" class="Email" placeholder="Email" value="" name="email-text"><br/><br/>
                <input type="text" placeholder="Password" value="" name="password-text"><br/><br/>
                <input type="submit" name="login-submit" value="Login"></button>
                <button type="button">Register</button>

            </form>
                <div id="php-code">
                <?php
                    /*$email_form = (isset($_POST['email-text'])) ? $_POST['email-text'] : '';
                    $pass_form = (isset($_POST['password-text'])) ? $_POST['password-text'] : '';
                    
                    // sql injection protection
                    $email_form = stripslashes($email_form);
                    $pass_form = stripslashes($pass_form);
                    $email_form = mysql_real_escape_string($email_form);
                    $pass_form = mysql_real_escape_string($pass_form);
                    
                    // login code
                    if (isset($_POST['login-submit'])) {
                        if (($email_form and $pass_form) != '') {
                            $check_ep = mysql_query("SELECT * FROM $db_user_inf WHERE email='$email_form' AND password='$pass_form'") or die ('query error: ' . mysql_error());
                            
                            if (mysql_num_rows($check_ep) == 1) {
                                $check_activation = mysql_query("SELECT * FROM $db_user_inf WHERE email='$email_form' AND activation=''");
                                
                                if (mysql_num_rows($check_activation) == 1) {
                             
                                    // set cookies then redicrect
                                    while($rows = mysql_fetch_array($check_activation))  {
                                        $_SESSION['user_name'] = $rows['Name'];
                                        $_SESSION['user_id'] = $rows['id'];
                                    }
                                    $_SESSION['user_email'] = $email_form;
                                    
                                      // check if all workouts for the user is there else create them
                                    $get_workouts = mysql_query("SELECT * FROM $db_workouts_name") or die(mysql_error());
                                    $get_workouts_num = mysql_num_rows($get_workouts);
                                    $myid = $_SESSION['user_id'];
                                    
                                    while($rows = mysql_fetch_array($get_workouts)){
                                        $chestarray[] = $rows['chest'];
                                        $tricepsarray[] = $rows['triceps'];
                                        $legsarray[] = $rows['legs'];
                                        $absarray[] = $rows['abs'];
                                        $shouldersarray[] = $rows['shoulders'];
                                        $bicepsarray[] = $rows['biceps'];
                                        $backarray[] = $rows['back'];   
                                    }
                                    
                                    for ($i=0; $i<=$get_workouts_num; $i++) {
                                        if ($chestarray[$i] != '')  {
                                            $j = mysql_query("SELECT * FROM chest WHERE id='$myid' AND name='$chestarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($j) == 0)    {
                                                mysql_query("INSERT INTO chest (id, name, kg_3) VALUES ('$myid', '$chestarray[$i]', '0')") or die(mysql_error());
                                                echo $chestarray[$i];
                                            }
                                        }
                                        if ($tricepsarray[$i] != '')  {
                                            $q = mysql_query("SELECT * FROM triceps WHERE id='$myid' AND name='$tricepsarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($q) == 0)    {
                                                mysql_query("INSERT INTO triceps (id, name, kg_3) VALUES ('$myid', '$tricepsarray[$i]', '0')");
                                            }
                                        }
                                        if ($legsarray[$i] != '')  {
                                            $k = mysql_query("SELECT * FROM legs WHERE id='$myid' AND name='$legsarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($k) == 0)    {
                                                mysql_query("INSERT INTO legs (id, name, kg_3) VALUES ('$myid', '$legsarray[$i]', '0')");
                                            }
                                        }
                                        if ($absarray[$i] != '')  {
                                            $l = mysql_query("SELECT * FROM abs WHERE id='$myid' AND name='$absarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($l) == 0)    {
                                                mysql_query("INSERT INTO abs (id, name, kg_3) VALUES ('$myid', '$absarray[$i]', '0')");
                                            }
                                        }
                                        if ($shouldersarray[$i] != '')  {
                                            $f = mysql_query("SELECT * FROM shoulders WHERE id='$myid' AND name='$shouldersarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($f) == 0)    {
                                                mysql_query("INSERT INTO shoulders (id, name, kg_3) VALUES ('$myid', '$shouldersarray[$i]', '0')");
                                            }
                                        }
                                        if ($bicepsarray[$i] != '')  {
                                            $w = mysql_query("SELECT * FROM biceps WHERE id='$myid' AND name='$bicepsarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($w) == 0)    {
                                                mysql_query("INSERT INTO biceps (id, name, kg_3) VALUES ('$myid', '$bicepsarray[$i]', '0')");
                                            }
                                        }
                                        if ($backarray[$i] != '')  {
                                            $h = mysql_query("SELECT * FROM back WHERE id='$myid' AND name='$backarray[$i]'") or die (mysql_error());
                                            if (mysql_num_rows($h) == 0)    {
                                                mysql_query("INSERT INTO back (id, name, kg_3) VALUES ('$myid', '$backarray[$i]', '0')");
                                            }
                                        }
                                    }
                                    mysql_close($connection);
                                    header('location: main.php');
                                }else {echo 'Your account have not been activated yet!';}
                            }else {echo '<p class="php-code">Your Email or Password is incorrect! <a href="forgot.php" style="color: #aabbaa">Click here if you forgot your password</a></p>';}
                        }else {echo '<p class="php-code">You leaved out one or more forms!</p>';}
                    }*/
                ?>
                </div>
            </div>
        </div>
    </head>
</html>